package com.liella.service.impl;


import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liella.entity.Video;
import com.liella.mapper.TVideoMapper;
import com.liella.model.vo.PageResult;
import com.liella.service.TVideoService;
import com.liella.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
* @author cys
* @description 针对表【t_video(视频表)】的数据库操作Service实现
* @createDate 2023-09-02 16:31:08
*/
@Service
public class TVideoServiceImpl extends ServiceImpl<TVideoMapper, Video>
implements TVideoService{
    @Autowired
    private TVideoMapper tVideoMapper;

    @Override
    public void saveVideo(Video video) {
        video.setCreatetime(new Date());
        video.setUpdatetime(new Date());
        video.setUserid((long) StpUtil.getLoginIdAsInt());
        boolean save = this.save(video);
        System.out.println(save);
    }

    @Override
    public PageResult<Video> pages() {
        Long count = tVideoMapper.selectCount(null);
        if (count == 0) {
            return new PageResult<>();
        }
        //通过分页拦截器直接获取分页参数放到PageUtils中
        List<Video> videos = tVideoMapper.selectVideoHomeList(PageUtils.getLimit(), PageUtils.getSize());
        return new PageResult<>(videos, count);
    }
}
